﻿Imports MySql.Data.MySqlClient
Public Class frmedit_booking
    Dim mysql As MySqlConnection = main_form.mysqlconection
    Dim mySqlCommand As New MySqlCommand
    Dim mySqlCommand1 As New MySqlCommand
    Dim mySqlAdaptor As New MySqlDataAdapter
    Dim mySqlReader As MySqlDataReader
    Dim respone As Object
    Dim consig As String
    Dim shipper As String
    Dim forwarder As String
    Dim idconsignee As String = "0"
    Dim consigneeid As String
    Dim shippingid As String
    Dim forwarderid As String
    Dim countstr1 As String = ""
    Dim fedstr As String = " "
    Dim fedboo As String = " "

    Dim mothstr As String = " "
    Dim mothboo As String = " "

    Dim ptranshipstr As String = " "
    Dim ptranshipboo As String = " "

    Dim ptranshipstr2 As String = " "
    Dim ptranshipboo2 As String = " "

    Dim dischargestr As String = " "
    Dim dischargeboo As String = " "

    Dim pdeliverlystr As String = " "
    Dim pdeliverlyboo As String = " "

    Dim fdestinationstr As String = " "
    Dim fdestinationboo As String = " "
    Dim checkINV As String = ""

    Dim inbtIndex As Integer

    Dim nicknameforward As String = " "
    Dim nicknameshipname As String = " "
    Private Sub frmedit_booking_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
        System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
        mySqlCommand.CommandText = "Select * from booking  left join shipper on booking.BSHIP = shipper.SHIPPERID where  BOOKINGID ='" & frmview_voyage.idbooking & "' ;"
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
                txt_booking_no.Text = mySqlReader("BNO")
                TextBox5.Text = mySqlReader("BNICKAGENT")
                TextBox3.Text = mySqlReader("BLANDNO")
                txt_type.Text = mySqlReader("BCTNTYPE")

                txt_notify.Text = mySqlReader("BNOTIFY")
                txt_scn.Text = mySqlReader("BSCN")
                txt_comodity.Text = mySqlReader("BCOM")
                txt_descript.Text = mySqlReader("BDESCRIPT")
                If mySqlReader("BTYPEMOVE") = 1 Then
                    RadioButton1.Checked = True
                ElseIf mySqlReader("BTYPEMOVE") = 2 Then
                    RadioButton2.Checked = True
                Else
                End If


                consig = mySqlReader("BCONSI")
                shipper = mySqlReader("BSHIP")

                TextBox2.Text = mySqlReader("SHIPADD")
                'TextBox1.Text = mySqlReader("SHIPADD")
                txt_TUG.Text = mySqlReader("BTUG")
                txt_Gross.Text = mySqlReader("BGROSS")

                TextBox4.Text = mySqlReader("BCTNNO")


                txt_localforwared.Text = mySqlReader("BLOCALFOR")
              
                If mySqlReader("BSHIPNAME") Is DBNull.Value Then
                Else
                    ComboBox2.Text = mySqlReader("BSHIPNAME")
                End If
                If mySqlReader("BFORWARDERNAME") Is DBNull.Value Then
                Else
                    ComboBox3.Text = mySqlReader("BFORWARDERNAME")
                End If
                If mySqlReader("POL") Is DBNull.Value Then
                Else
                    txt_pol.Text = mySqlReader("POL")
                End If
                If mySqlReader("TSPORT") Is DBNull.Value Then
                Else
                    txt_tsport.Text = mySqlReader("TSPORT")
                End If
                If mySqlReader("REMARK") Is DBNull.Value Then
                Else
                    txt_remark.Text = mySqlReader("REMARK")
                End If

               


                nicknameforward = mySqlReader("BNFORWARDERNAME")
                nicknameshipname = mySqlReader("BNSHIPNAME")



                If mySqlReader("BCHECKLOAD") Is DBNull.Value Then
                    RadioButton6.Checked = True
                Else
                    If mySqlReader("BCHECKLOAD") = "True" Then
                        RadioButton5.Checked = True
                    ElseIf mySqlReader("BCHECKLOAD") = "False" Then

                        RadioButton6.Checked = True
                    End If
                End If

                If mySqlReader("BINVOICE") Is DBNull.Value Then

                Else
                    TextBoxX2.Text = mySqlReader("BINVOICE")
                End If
                If mySqlReader("BINCOTERM") Is DBNull.Value Then

                Else
                    TextBoxX4.Text = mySqlReader("BINCOTERM")
                End If

                If mySqlReader("BREMARK") Is DBNull.Value Then

                Else
                    TextBoxX5.Text = mySqlReader("BREMARK")
                End If


                TextBoxX6.Text = mySqlReader("BMOTH")
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()

        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If

        mySqlCommand.CommandText = "Select * from booking left  join shipper  on booking.BFORWARDER = shipper.SHIPPERID where  BOOKINGID ='" & frmview_voyage.idbooking & "' ;"
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader
            While (mySqlReader.Read())
                ComboBox3.Text = mySqlReader("SHIPNAME")
                TextBox1.Text = mySqlReader("SHIPADD")
            End While
        Catch ex As Exception

        End Try
        mysql.Close()





        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If


        mySqlCommand.CommandText = "Select * from booking_bl_ctn where bookid = '" & frmview_voyage.idbooking & "' order By idbooking_bl_ctn ASC;"
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())

                DataGridViewX2.Rows.Add({mySqlReader("name_1"), mySqlReader("name_2")})


            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()





























        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If


        mySqlCommand.CommandText = "Select * from shipper;"
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
                ComboBox2.Items.Add(mySqlReader("SHIPNAME"))

            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()


     



        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If


        mySqlCommand.CommandText = "Select * from shipper;"
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
                ComboBox3.Items.Add(mySqlReader("SHIPNAME"))

            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()



        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If


        mySqlCommand.CommandText = "Select * from consignee;"
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
                ComboBox1.Items.Add(mySqlReader("CONNAME"))

            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()


        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If


        mySqlCommand.CommandText = "Select count(idbooking_bl) as count1 from booking_bl where booking_id= '" & frmview_voyage.idbooking & "';"
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
                countstr1 = mySqlReader("count1")

            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()


        If countstr1 = "0" Then



        Else
            mysql.Close()


            If mysql.State = ConnectionState.Closed Then
                mysql.Open()
            End If

            mySqlCommand.CommandText = "Select * from booking_bl where booking_id= '" & frmview_voyage.idbooking & "';"
            mySqlCommand.Connection = mysql
            mySqlAdaptor.SelectCommand = mySqlCommand

            Try
                mySqlReader = mySqlCommand.ExecuteReader

                While (mySqlReader.Read())
                    TextBoxX3.Text = mySqlReader("billbooking")
                    TextBoxX13.Text = mySqlReader("number")
                    TextBoxX1.Text = mySqlReader("number_word")
                    TextBoxX7.Text = mySqlReader("place")
                    idconsignee = mySqlReader("conid")
                End While
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            mysql.Close()


            If mysql.State = ConnectionState.Closed Then
                mysql.Open()
            End If


            mySqlCommand.CommandText = "Select * from consignee where consigneeid = '" & idconsignee & "' ;"
            mySqlCommand.Connection = mysql
            mySqlAdaptor.SelectCommand = mySqlCommand

            Try
                mySqlReader = mySqlCommand.ExecuteReader

                While (mySqlReader.Read())
                    ComboBox1.Text = mySqlReader("CONNAME")
                    TextBox6.Text = mySqlReader("CONADD").ToString
                End While
            Catch ex As Exception

            End Try
            mysql.Close()

        End If





    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click



        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
        Try

            Dim checkradio2 As String
            If RadioButton1.Checked = True Then
                checkradio2 = "1"

            ElseIf RadioButton2.Checked = True Then
                checkradio2 = "2"
            End If

            If RadioButton5.Checked = True Then
                checkINV = "True"
            ElseIf RadioButton6.Checked = True Then
                checkINV = "False"
            End If
            mySqlCommand.Parameters.Clear()
        
            mySqlCommand.CommandText = "UPDATE booking SET BLOCALFOR ='" & txt_localforwared.Text & "' , BNO = '" & MySqlHelper.EscapeString(txt_booking_no.Text) & "' , BCTNNO = '" & TextBox4.Text & "', BLANDNO = '" & TextBox3.Text & "' ,BCTNTYPE ='" & MySqlHelper.EscapeString(txt_type.Text) & "',BLANDNO ='" & MySqlHelper.EscapeString(TextBox3.Text) & "',BNOTIFY = '" & MySqlHelper.EscapeString(txt_notify.Text) & "', BSCN = '" & MySqlHelper.EscapeString(txt_scn.Text) & "',BCOM ='" & MySqlHelper.EscapeString(txt_comodity.Text) & "',BDESCRIPT = '" & MySqlHelper.EscapeString(txt_descript.Text) & "' ,POL = '" & MySqlHelper.EscapeString(txt_pol.Text) & "',TSPORT = '" & MySqlHelper.EscapeString(txt_tsport.Text) & "',BCONSI = '" & MySqlHelper.EscapeString(idconsignee) & "'  ,BSHIP = '" & MySqlHelper.EscapeString(shipper) & "' ,BCONSINAME = '' ,BSHIPNAME = '" & MySqlHelper.EscapeString(ComboBox2.Text) & "' ,REMARK = '" & MySqlHelper.EscapeString(txt_remark.Text) & "' ,  BNSHIPNAME = '" & nicknameshipname & "', BNFORWARDERNAME ='" & nicknameforward & "' , BGROSS ='" & txt_Gross.Text & "' , BTUG ='" & txt_TUG.Text & "', BPORTDIS ='" & dischargestr & "' , BPORTDISS = '" & dischargeboo & "',BNICKAGENT ='" & TextBox5.Text & "',BFORWARDERNAME ='" & ComboBox3.Text & "'  ,BFORWARDER = '" & forwarderid & "', BCHECKLOAD ='" & checkINV & "',BINVOICE ='" & MySqlHelper.EscapeString(TextBoxX2.Text) & "' , BINCOTERM ='" & MySqlHelper.EscapeString(TextBoxX4.Text) & "' , BREMARK ='" & MySqlHelper.EscapeString(TextBoxX5.Text) & "', BMOTH ='" & MySqlHelper.EscapeString(TextBoxX6.Text) & "' WHERE BOOKINGID = '" & frmview_voyage.idbooking & "'; "

            mySqlCommand.CommandType = CommandType.Text
            mySqlCommand.Connection = mysql

            mySqlCommand.ExecuteNonQuery()
            mysql.Close()

          
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try



        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
        Try

            mySqlCommand.CommandText = "DELETE FROM booking_bl_ctn where bookid = '" & frmview_voyage.idbooking & "';"
            mySqlCommand.CommandType = CommandType.Text
            mySqlCommand.Connection = mysql

            mySqlCommand.ExecuteNonQuery()
            mysql.Close()

        Catch ex As Exception

            MsgBox(ex.ToString)
            Exit Sub
        End Try




        If DataGridViewX2.Rows.Count > 0 Then
            For i = 0 To DataGridViewX2.Rows.Count - 2
                If mysql.State = ConnectionState.Closed Then
                    mysql.Open()
                End If
                Try
                    mySqlCommand.Parameters.Clear()
                    mySqlCommand.CommandText = "insert into booking_bl_ctn (idnumber, bookid, name_1, name_2) values (@idnumber,@bookid,@name_1,@name_2)"
                    mySqlCommand.Connection = mysql


                    mySqlCommand.Parameters.AddWithValue("@idnumber", i)
                    mySqlCommand.Parameters.AddWithValue("@bookid", frmview_voyage.idbooking)
                    mySqlCommand.Parameters.AddWithValue("@name_1", DataGridViewX2.Rows(i).Cells(0).Value)
                    mySqlCommand.Parameters.AddWithValue("@name_2", DataGridViewX2.Rows(i).Cells(1).Value)
                    mySqlCommand.ExecuteNonQuery()
                    mysql.Close()
                Catch ex As Exception
                    MsgBox(ex.ToString)
                End Try

                mysql.Close()
            Next

        End If




        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
        Try

            mySqlCommand.CommandText = "DELETE FROM booking_bl where booking_id = '" & frmview_voyage.idbooking & "';"
            mySqlCommand.CommandType = CommandType.Text
            mySqlCommand.Connection = mysql

            mySqlCommand.ExecuteNonQuery()
            mysql.Close()

        Catch ex As Exception

            MsgBox(ex.ToString)
            Exit Sub
        End Try
        Dim idlast As Integer
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If
        mySqlCommand.Parameters.Clear()
        mySqlCommand.CommandText = "insert into booking_bl (billbooking, number, place, conid,conname,conaddress,booking_id,number_word) values (@billbooking,@number,@place,@conid,@conname,@conaddress,@booking_id,@number_word);  SELECT LAST_INSERT_ID()"
        mySqlCommand.Connection = mysql


        mySqlCommand.Parameters.AddWithValue("@billbooking", TextBoxX3.Text)
        mySqlCommand.Parameters.AddWithValue("@number", TextBoxX13.Text)
        mySqlCommand.Parameters.AddWithValue("@place", TextBoxX7.Text)
        mySqlCommand.Parameters.AddWithValue("@conid", idconsignee)
        mySqlCommand.Parameters.AddWithValue("@conname", ComboBox1.Text)
        mySqlCommand.Parameters.AddWithValue("@conaddress", TextBox6.Text)
        mySqlCommand.Parameters.AddWithValue("@booking_id", frmview_voyage.idbooking)
        mySqlCommand.Parameters.AddWithValue("@number_word", TextBoxX1.Text)
        idlast = mySqlCommand.ExecuteScalar()



        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If


        mySqlCommand.CommandText = "UPDATE booking SET BINV='" & idlast & "'   WHERE BOOKINGID = '" & frmview_voyage.idbooking & "'; "

        mySqlCommand.CommandType = CommandType.Text
        mySqlCommand.Connection = mysql

        mySqlCommand.ExecuteNonQuery()
        mysql.Close()

        mysql.Close()


        Dim cf As New frmview_voyage

        cf.MdiParent = Me.MdiParent
        Me.Close()
        cf.Dock = DockStyle.Fill
        cf.Show()




    End Sub

    Private Sub ComboBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox2.KeyDown
        If e.KeyCode = Keys.Enter Then
            mysql.Close()
            Dim check1 As String = "0"

            If mysql.State = ConnectionState.Closed Then
                mysql.Open()
            End If
            mySqlCommand.CommandText = "Select  count(shipperid) as ship from  shipper where SHIPNAME like '" & Trim(ComboBox2.Text) & "%';"
            mySqlCommand.Connection = mysql
            mySqlAdaptor.SelectCommand = mySqlCommand

            Try
                mySqlReader = mySqlCommand.ExecuteReader

                'MsgBox(mySqlReader.FieldCount.ToString)
                While (mySqlReader.Read())

                    check1 = mySqlReader("ship")


                End While
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
            If check1 = "1" Then
                mysql.Close()
                If mysql.State = ConnectionState.Closed Then
                    mysql.Open()
                End If
                mySqlCommand.CommandText = "Select  * from  shipper where SHIPNAME like '" & Trim(ComboBox2.Text) & "%';"
                mySqlCommand.Connection = mysql
                mySqlAdaptor.SelectCommand = mySqlCommand

                Try
                    mySqlReader = mySqlCommand.ExecuteReader

                    'MsgBox(mySqlReader.FieldCount.ToString)
                    While (mySqlReader.Read())
                        shippingid = mySqlReader("SHIPPERID")
                        ComboBox2.Text = mySqlReader("SHIPNAME")
                        TextBox2.Text = mySqlReader("SHIPADD")
                        nicknameshipname = mySqlReader("SHIPNICKNAME")
                    End While
                Catch ex As Exception

                End Try

            End If

        End If



    End Sub

     

    Private Sub ComboBox2_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedValueChanged
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If

        mySqlCommand.CommandText = "Select * from  shipper where SHIPNAME = '" & Trim(ComboBox2.Text) & "';"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
                shipper = mySqlReader("SHIPPERID")
                ComboBox2.Text = mySqlReader("SHIPNAME")
                TextBox2.Text = mySqlReader("SHIPADD")
                nicknameshipname = mySqlReader("SHIPNICKNAME")
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()
    End Sub

    Private Sub ComboBox3_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox3.KeyDown
        If e.KeyCode = Keys.Enter Then
            Dim check1 As String = "0"
            mysql.Close()

            If mysql.State = ConnectionState.Closed Then
                mysql.Open()
            End If

            mySqlCommand.CommandText = "Select  count(shipperid) as ship  from  shipper where SHIPNAME like '" & Trim(ComboBox3.Text) & "%';"
            mySqlCommand.Connection = mysql
            mySqlAdaptor.SelectCommand = mySqlCommand

            Try
                mySqlReader = mySqlCommand.ExecuteReader

                'MsgBox(mySqlReader.FieldCount.ToString)
                While (mySqlReader.Read())

                    check1 = mySqlReader("ship")


                End While
            Catch ex As Exception

            End Try
            If check1 = "1" Then
                mysql.Close()

                If mysql.State = ConnectionState.Closed Then
                    mysql.Open()
                End If

                mySqlCommand.CommandText = "Select * from  shipper where SHIPNAME like '" & Trim(ComboBox3.Text) & "%';"
                mySqlCommand.Connection = mysql
                mySqlAdaptor.SelectCommand = mySqlCommand

                Try
                    mySqlReader = mySqlCommand.ExecuteReader

                    'MsgBox(mySqlReader.FieldCount.ToString)
                    While (mySqlReader.Read())
                        forwarderid = mySqlReader("SHIPPERID")
                        ComboBox3.Text = mySqlReader("SHIPNAME")
                        TextBox1.Text = mySqlReader("SHIPADD")
                        nicknameforward = mySqlReader("SHIPNICKNAME")


                    End While
                Catch ex As Exception

                End Try
            End If


        End If

        mysql.Close()

    End Sub

    Private Sub ComboBox3_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedValueChanged
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If

        mySqlCommand.CommandText = "Select * from  shipper where SHIPNAME = '" & Trim(ComboBox3.Text) & "';"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
                forwarder = mySqlReader("SHIPPERID")
                ComboBox3.Text = mySqlReader("SHIPNAME")
                TextBox1.Text = mySqlReader("SHIPADD")
                nicknameforward = mySqlReader("SHIPNICKNAME")

            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()
    End Sub

    Private Sub GroupBox5_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox5.Enter

    End Sub

    Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
        Dim cf As New frmview_voyage

        cf.MdiParent = Me.MdiParent
        Me.Close()
        cf.Dock = DockStyle.Fill
        cf.Show()
    End Sub
 

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If

        mySqlCommand.CommandText = "Select * from  shipper where SHIPNAME = '" & Trim(ComboBox2.Text) & "';"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
                shipper = mySqlReader("SHIPPERID")
                ComboBox2.Text = mySqlReader("SHIPNAME")
                TextBox2.Text = mySqlReader("SHIPADD")
                nicknameshipname = mySqlReader("SHIPNICKNAME")
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()
    End Sub

    Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If

        mySqlCommand.CommandText = "Select * from  shipper where SHIPNAME = '" & Trim(ComboBox3.Text) & "';"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
      
                forwarderid = mySqlReader("SHIPPERID")
                ComboBox3.Text = mySqlReader("SHIPNAME")
                TextBox1.Text = mySqlReader("SHIPADD")
                nicknameforward = mySqlReader("SHIPNICKNAME")
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()
    End Sub

    Private Sub DataGridViewX2_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridViewX2.CellClick
        inbtIndex = e.RowIndex


    End Sub

    Private Sub DataGridViewX1_CellMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridViewX2.CellMouseDown

        Try
            Dim rowClicked As DataGridView.HitTestInfo = DataGridViewX2.HitTest(e.X, e.Y)
            'Select Right Clicked Row if its not the header row
            If e.Button = Windows.Forms.MouseButtons.Right AndAlso e.RowIndex > -1 Then
                'Clear any currently sellected rows
                DataGridViewX2.CurrentCell = DataGridViewX2.Rows(e.RowIndex).Cells(e.ColumnIndex)

                ContextMenuStrip1.Show(DataGridViewX2, New Point(e.RowIndex, e.ColumnIndex))

            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Mark_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Mark.Click
        DataGridViewX2.Rows.Remove(DataGridViewX2.CurrentRow)
    End Sub
    Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
        mysql.Close()
        If mysql.State = ConnectionState.Closed Then
            mysql.Open()
        End If

        mySqlCommand.CommandText = "Select * from  consignee where CONNAME = '" & Trim(ComboBox1.Text) & "';"
        mySqlCommand.Connection = mysql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            While (mySqlReader.Read())
                idconsignee = mySqlReader("CONSIGNEEID")
                ComboBox1.Text = mySqlReader("CONNAME")
                TextBox6.Text = mySqlReader("CONADD")
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        mysql.Close()
    End Sub
    Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
        If e.KeyCode = Keys.Enter Then
            Dim check1 As String = "0"
            mysql.Close()

            If mysql.State = ConnectionState.Closed Then
                mysql.Open()
            End If

            mySqlCommand.CommandText = "Select  count(CONSIGNEEID) as ship  from  consignee where CONNAME like '%" & Trim(ComboBox1.Text) & "%';"
            mySqlCommand.Connection = mysql
            mySqlAdaptor.SelectCommand = mySqlCommand

            Try
                mySqlReader = mySqlCommand.ExecuteReader

                'MsgBox(mySqlReader.FieldCount.ToString)
                While (mySqlReader.Read())

                    check1 = mySqlReader("ship")


                End While
            Catch ex As Exception

            End Try
            If check1 = "1" Then
                mysql.Close()

                If mysql.State = ConnectionState.Closed Then
                    mysql.Open()
                End If

                mySqlCommand.CommandText = "Select *   from  consignee where CONNAME like '" & Trim(ComboBox1.Text) & "%';"
                mySqlCommand.Connection = mysql
                mySqlAdaptor.SelectCommand = mySqlCommand

                Try
                    mySqlReader = mySqlCommand.ExecuteReader

                    'MsgBox(mySqlReader.FieldCount.ToString)
                    While (mySqlReader.Read())
                        idconsignee = mySqlReader("CONSIGNEEID")
                        ComboBox1.Text = mySqlReader("CONNAME")
                        TextBox6.Text = mySqlReader("CONADD")


                    End While
                Catch ex As Exception

                End Try
            End If


        End If

        mysql.Close()


    End Sub

    Private Sub TextBoxX13_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBoxX13.KeyDown
        If e.KeyCode = Keys.Enter Then
            TextBoxX1.Text = AmtInWord(TextBoxX13.Text)
        Else

        End If
    End Sub

    Private Sub MotherVesselToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MotherVesselToolStripMenuItem.Click
        TextBoxX6.Text = DataGridViewX2.Rows(inbtIndex).Cells(1).Value
    End Sub
End Class